package com.fourool.goodsmall.controller;

import com.fourool.goodsmall.common.Result;
import com.fourool.goodsmall.dto.CreateOrderDTO;
import com.fourool.goodsmall.dto.OrderPayDTO;
import com.fourool.goodsmall.service.GOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private GOrderService orderService;

    // 订单上传
    @PostMapping("/create")
    public Result create(@RequestBody CreateOrderDTO dto) {
        return orderService.createOrder(dto);
    }

    // 根据用户id获取订单列表，通过status控制
    @GetMapping("/list/{pid}")
    public Result list(@PathVariable Integer pid, @RequestParam(required = false) Integer status) {
        return orderService.getOrderList(pid, status);
    }

    // 订单详情
    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable Integer id) {
        return orderService.getOrderDetail(id);
    }

    // 订单支付
    @PostMapping("/pay")
    public Result pay(@RequestBody OrderPayDTO dto) {
        Result r = orderService.payOrder(dto);
        return r;
    }

    // 取消订单
    @PutMapping("/cancel/{id}")
    public Result cancel(@PathVariable Integer id) {
        return orderService.cancelOrder(id);
    }
}